/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ytmc;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 *
 * @author K
 */
public class RemoteImageView extends PanelView
{
    private BufferedImage image;

    private String imegeURL;

    public String getImegeURL()
    {
        return imegeURL;
    }

    public void setImegeURL(String imegeURL)
    {
        if(!this.imegeURL.equals(imegeURL))
        {
            this.imegeURL = imegeURL;
            onImageURLChanged();
        }
    }

    private void onImageURLChanged()
    {
        try
        {
            URL url = new URL(imegeURL);
            image = ImageIO.read(url);
        }
        catch (MalformedURLException ex)
        {
            Logger.getLogger(RemoteImageView.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IOException ex)
        {
            Logger.getLogger(RemoteImageView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public RemoteImageView()
    {
        this.imegeURL = "";
    }

    @Override
    public void paintComponent(Graphics g)
    {
        if(image != null)
        {
            g.drawImage(image, 0, 0, null);
        }
    }
}
